package tech.aistar.controller;


import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.dto.HeSearch;
import tech.aistar.entity.House;
import tech.aistar.entity.Result;
import tech.aistar.service.ICostService;
import tech.aistar.service.IES;
import tech.aistar.service.IEnvironmentFacilityService;
import tech.aistar.service.IHouseService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/House")
public class HouseAction {
    @Autowired
    private IHouseService houseService;
    @Autowired
    private ICostService costService;
    @Autowired
    private IEnvironmentFacilityService environmentFacilityService;
    @Autowired
    private IES ies;

    @RequestMapping("/Map")
    public String Map(){
        return "/map/map";
    }

    //=============================合租 - 房源设施=======================================
    @RequestMapping("/Hezu")
    public String HeZu(HttpServletRequest request,HttpServletResponse response) {
        String lab = null;
        String identity = null;
        String min = null;
        String max = null;
        String type = null;
        String chao = null;
        response.setContentType("text/json;charset=utf-8");
        String box1 = request.getParameter("box1");
        String box2 = request.getParameter("box2");
        String box3 = request.getParameter("box3");
        String box4 = request.getParameter("box4");
        String box5 = request.getParameter("box5");
        String box6 = request.getParameter("box6");
        String box7 = request.getParameter("box7");
        String box8 = request.getParameter("box8");
        String box9 = request.getParameter("box9");
        String box10 = request.getParameter("box10");
        String box11 = request.getParameter("box11");
        String box12 = request.getParameter("box12");
        String box13 = request.getParameter("box13");
        String box14 = request.getParameter("box14");
        String boxa = request.getParameter("boxa");
        String boxb = request.getParameter("boxb");
        String boxc = request.getParameter("boxc");
        String boxd = request.getParameter("boxd");
        String boxe = request.getParameter("boxe");
        String boxf = request.getParameter("boxf");

        if (request.getParameter("lab") != "") {
            lab = request.getParameter("lab");
        }

        if (request.getParameter("identity") != "") {
            identity = request.getParameter("identity");
        }

        if (request.getParameter("min") != "") {
            min = request.getParameter("min");
        }
        if (request.getParameter("max") != "") {
            max = request.getParameter("max");
        }
        if (request.getParameter("huType") != "") {
            type = request.getParameter("huType");
        }
        if (request.getParameter("chao") != "") {
            chao = request.getParameter("chao");
        }
        String pageNow = request.getParameter("pageNow");
        pageNow = pageNow == null ? "1" : pageNow;

        PageInfo<House> pageInfo = houseService.houseAllHeFacilityPage(lab,identity,min, max, type, chao,
                boxa, boxe, boxf, boxb, box1,
                box2, box5, box4, box3, box6,
                box7, box13, box12, box11, boxc,
                boxd, box8, box14, box10, box9,
                Integer.valueOf(pageNow), 8);
        request.setAttribute("page", pageInfo);

        return "/rent/hezuyemian";
    }

    @GetMapping("/HezuSec/{sea}")
    public  String HeZuSec(
            @PathVariable("sea") String sea,
            HttpServletRequest request,HttpServletResponse response) {
//        System.out.println(sea);
        //调用ES搜索方法
        List<Map<String, Object>> house = ies.searchEs(sea);
//        PageInfo<Object> pageInfo = ies.heESPage(sea,1, 8);
//        for (Map<String, Object> map : house) {
//            for (String s : map.keySet()) {
//                System.out.println(s+":"+map.get(s));
//            }
//        }
//        PageInfo<HeSearch> pageInfo = ies.heESPage(sea,1,8);

        request.setAttribute("zw","none");

        request.setAttribute("house",house);

        return "/rent/hezuyemian";
    }


    @RequestMapping("/HezuCheck")
    public @ResponseBody
    Result HeZuTwo(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/json;charset=utf-8");

        String lab = null;
        String min = null;
        String max = null;
        String identity = null;
        String type = null;
        String chao = null;
        String box1 = request.getParameter("box1");
        String box2 = request.getParameter("box2");
        String box3 = request.getParameter("box3");
        String box4 = request.getParameter("box4");
        String box5 = request.getParameter("box5");
        String box6 = request.getParameter("box6");
        String box7 = request.getParameter("box7");
        String box8 = request.getParameter("box8");
        String box9 = request.getParameter("box9");
        String box10 = request.getParameter("box10");
        String box11 = request.getParameter("box11");
        String box12 = request.getParameter("box12");
        String box13 = request.getParameter("box13");
        String box14 = request.getParameter("box14");
        String boxa = request.getParameter("boxa");
        String boxb = request.getParameter("boxb");
        String boxc = request.getParameter("boxc");
        String boxd = request.getParameter("boxd");
        String boxe = request.getParameter("boxe");
        String boxf = request.getParameter("boxf");


        if (request.getParameter("lab") != "") {
            lab = request.getParameter("lab");
        }

        if (request.getParameter("min") != "") {
            min = request.getParameter("min");
        }
        if (request.getParameter("max") != "") {
            max = request.getParameter("max");
        }

        if (request.getParameter("identity") != "") {
            identity = request.getParameter("identity");
        }

        if (request.getParameter("huType") != "") {
            type = request.getParameter("huType");
        }
        if (request.getParameter("chao") != "") {
            chao = request.getParameter("chao");
        }

        String pageNow = request.getParameter("pageNow");
        pageNow = pageNow == "" ? "1" : pageNow;

        PageInfo<House> pageInfo = houseService.houseAllHeFacilityPage(lab,identity,min, max, type, chao,
                boxa, boxe, boxf, boxb, box1,
                box2, box5, box4, box3, box6,
                box7, box13, box12, box11, boxc,
                boxd, box8, box14, box10, box9,
                Integer.valueOf(pageNow), 8);
//        pageInfo.getList().forEach(e-> System.out.println(e));
        Result result = new Result("200", "成功", pageInfo);

        return result;
    }

    @GetMapping("/HezuInfo")
    public String HezuInfo(HttpServletRequest request, Integer id) {
        House house = (House) houseService.findById(id);
        request.setAttribute("house", house);
        return "/rent_info/hezufangyuanxinxi";
    }


    //==========================整租 - 房源设施 ===============
    @RequestMapping("/Zheng")
    public String Zheng(HttpServletRequest request,HttpServletResponse response) {
        String lab = null;
        String identity = null;
        String min = null;
        String max = null;
        String type = null;
        String chao = null;
        response.setContentType("text/json;charset=utf-8");
        String box1 = request.getParameter("box1");
        String box2 = request.getParameter("box2");
        String box3 = request.getParameter("box3");
        String box4 = request.getParameter("box4");
        String box5 = request.getParameter("box5");
        String box6 = request.getParameter("box6");
        String box7 = request.getParameter("box7");
        String box8 = request.getParameter("box8");
        String box9 = request.getParameter("box9");
        String box10 = request.getParameter("box10");
        String box11 = request.getParameter("box11");
        String box12 = request.getParameter("box12");
        String box13 = request.getParameter("box13");
        String box14 = request.getParameter("box14");
        String boxa = request.getParameter("boxa");
        String boxb = request.getParameter("boxb");
        String boxc = request.getParameter("boxc");
        String boxd = request.getParameter("boxd");
        String boxe = request.getParameter("boxe");
        String boxf = request.getParameter("boxf");

        if (request.getParameter("lab") != "") {
            lab = request.getParameter("lab");
        }

        if (request.getParameter("identity") != "") {
            identity = request.getParameter("identity");
        }

        if (request.getParameter("min") != "") {
            min = request.getParameter("min");
        }
        if (request.getParameter("max") != "") {
            max = request.getParameter("max");
        }
        if (request.getParameter("huType") != "") {
            type = request.getParameter("huType");
        }
        if (request.getParameter("chao") != "") {
            chao = request.getParameter("chao");
        }
        String pageNow = request.getParameter("pageNow");
        pageNow = pageNow == null ? "1" : pageNow;

        PageInfo<House> pageInfo = houseService.houseAllZhengFacilityPage(lab,identity,min, max, type, chao,
                boxa, boxe, boxf, boxb, box1,
                box2, box5, box4, box3, box6,
                box7, box13, box12, box11, boxc,
                boxd, box8, box14, box10, box9,
                Integer.valueOf(pageNow), 8);
        request.setAttribute("page", pageInfo);
        return "/rent/zhengzuyemian";
    }

    @GetMapping("/zhengSec/{sea}")
    public  String zhengSec(
            @PathVariable("sea") String sea,
            HttpServletRequest request,HttpServletResponse response) {
//        System.out.println(sea);
        //调用ES搜索方法
        List<Map<String, Object>> house = ies.searchEsZheng(sea);
//        for (Map<String, Object> map : house) {
//            for (String s : map.keySet()) {
//                System.out.println(s+":"+map.get(s));
//            }
//        }

        request.setAttribute("zw","none");

        request.setAttribute("house",house);

        return "/rent/zhengzuyemian";
    }


    @RequestMapping("/ZhengCheck")
    public @ResponseBody
    Result ZhengTwo(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/json;charset=utf-8");
        String lab = null;
        String min = null;
        String max = null;
        String identity = null;
        String type = null;
        String chao = null;
        String box1 = request.getParameter("box1");
        String box2 = request.getParameter("box2");
        String box3 = request.getParameter("box3");
        String box4 = request.getParameter("box4");
        String box5 = request.getParameter("box5");
        String box6 = request.getParameter("box6");
        String box7 = request.getParameter("box7");
        String box8 = request.getParameter("box8");
        String box9 = request.getParameter("box9");
        String box10 = request.getParameter("box10");
        String box11 = request.getParameter("box11");
        String box12 = request.getParameter("box12");
        String box13 = request.getParameter("box13");
        String box14 = request.getParameter("box14");
        String boxa = request.getParameter("boxa");
        String boxb = request.getParameter("boxb");
        String boxc = request.getParameter("boxc");
        String boxd = request.getParameter("boxd");
        String boxe = request.getParameter("boxe");
        String boxf = request.getParameter("boxf");


        if (request.getParameter("lab") != "") {
            lab = request.getParameter("lab");
        }

        if (request.getParameter("min") != "") {
            min = request.getParameter("min");
        }
        if (request.getParameter("max") != "") {
            max = request.getParameter("max");
        }

        if (request.getParameter("identity") != "") {
            identity = request.getParameter("identity");
        }

        if (request.getParameter("huType") != "") {
            type = request.getParameter("huType");
        }
        if (request.getParameter("chao") != "") {
            chao = request.getParameter("chao");
        }

        String pageNow = request.getParameter("pageNow");
        pageNow = pageNow == "" ? "1" : pageNow;

        PageInfo<House> pageInfo = houseService.houseAllZhengFacilityPage(
                lab,identity,min, max, type, chao,
                boxa, boxe, boxf, boxb, box1,
                box2, box5, box4, box3, box6,
                box7, box13, box12, box11, boxc,
                boxd, box8, box14, box10, box9,
                Integer.valueOf(pageNow), 8);
//        pageInfo.getList().forEach(e-> System.out.println(e));
        Result result = new Result("200", "成功", pageInfo);

        return result;
    }



    @GetMapping("/ZhengInfo")
    public String ZhengInfo(HttpServletRequest request, Integer id) {
        House house = (House) houseService.findById(id);
        request.setAttribute("house", house);
        return "/rent_info/zhengzufangyuanxinxi";
    }


//
    //============接受个人中心传来的参数==================
    @RequestMapping("/zhengjie")
    public String zhengJie(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/json;charset=utf-8");
        String fridge = request.getParameter("fridge");
        String television = request.getParameter("television");
        String airCondition = request.getParameter("airCondition");
        String geyser = request.getParameter("geyser");
        String washingMachine = request.getParameter("washingMachine");
        String broadband = request.getParameter("broadband");
        String sofa = request.getParameter("sofa");
        String balcony = request.getParameter("balcony");
        String gasStove = request.getParameter("gasStove");
        String rangeHood = request.getParameter("rangeHood");
        String wardrobe = request.getParameter("wardrobe");
        String heat = request.getParameter("heat");
        String bed = request.getParameter("bed");
        String intelligentLock = request.getParameter("intelligentLock");
        String greenery = request.getParameter("greenery");
        String schoolNearbyHouse = request.getParameter("schoolNearbyHouse");
        String cookingable = request.getParameter("cookingable");
        String bathroom = request.getParameter("bathroom");
        String trafficConvenient = request.getParameter("trafficConvenient");
        String shoppingConvenient = request.getParameter("shoppingConvenient");

//        String green, String traffic,String shop, String school, String fridge,
//                String tv,String wash,String geyser, String air,String broad,
//                String sofa, String bed, String heat, String wardrobe, String cook,
//                String bath, String balcony, String lock,String hood, String stove

//        String pageNow = request.getParameter("pageNow");
//        pageNow = pageNow == "" ? "1" : pageNow;

        PageInfo<House> pageInfo = houseService.houseAllZhengFacilityPage(
                null,null,null,null,null,null,
                greenery, trafficConvenient, shoppingConvenient,schoolNearbyHouse ,fridge,
                television, washingMachine, geyser, airCondition, broadband,
                sofa, bed, heat, wardrobe, cookingable,
                bathroom, balcony, intelligentLock, rangeHood, gasStove,
                1, 8);

        request.setAttribute("page", pageInfo);

        return "/rent/zhengzuyemian";
    }


    @RequestMapping("/ZhengType")
    public String ZhengType(HttpServletRequest request) {
        String houseType = request.getParameter("houseType");//户型
        String orientate = request.getParameter("orientate");//朝向

        PageInfo<House> pageInfo = houseService.houseAllZhengFacilityPage(
                null,null,null,null,houseType,orientate,
                "false", "false", "false","false" ,"false",
                "false", "false", "false", "false", "false",
                "false", "false", "false", "false", "false",
                "false", "false", "false", "false", "false",
                1, 8);
//        PageInfo<House> pageInfo = houseService.finalZhengPage(null, null, null, houseType, orientate, 1, 8);
//        pageInfo.getList().forEach(e-> System.out.println(e));
        request.setAttribute("page", pageInfo);

        return "/rent/zhengzuyemian";
    }


}